
package oreilly.command.control;

/**
 * 模擬風扇打開的 command<br>
 * <br>
 * Copyright: Copyright (c) 2002-2007<br>
 * Company: E885 有限公司
 * 
 * @author Eric Gau(E-mail:gau168.gau@msa.hinet.net)
 * @version 1.0
 */
public class FanOnCommand implements Command
{
	/**
	 * 風扇先前的速度
	 */
	private int previousSpeed;

	/**
	 * 風扇的主體
	 */
	private Fan fan;

	/**
	 * constructor
	 * 
	 * @param fan 風扇主體
	 */
	public FanOnCommand( Fan fan )
	{
		this.fan = fan;
	}

	/**
	 * 當打開風扇, 速度預設為 slow
	 * 
	 * @see Command#execute()
	 */
	public void execute()
	{
		previousSpeed = fan.getSpeed();

		fan.slow();
	}

	/**
	 * @see Command#undo()
	 */
	public void undo()
	{
		if( previousSpeed == Fan.OFF )
		{
			fan.turnOff();
		}
		else if( previousSpeed == Fan.SLOW_SPEED )
		{
			fan.slow();
		}
		else if( previousSpeed == Fan.MEDIUM_SPEED )
		{
			fan.medium();
		}
		else if( previousSpeed == Fan.HIGH_SPEED )
		{
			fan.hight();
		}
	}
}
